from django.contrib import admin
from goods.models import Goods,SKU,SKUImage
from contents.utils import generate_static_index_html
from celery_tasks.static_html.tasks import generate_static_list_search_html,generate_static_sku_detail_html
# Register your models here.

#后台详情页面展示
class GoodsAdmin(admin.ModelAdmin):
    # 需要展示的属性
    list_display = ['id','name','sales']

    # 修改商品信息后 触发保存操作
    def save_model(self, request, obj, form, change):
        obj.save()
        generate_static_list_search_html.delay()
        # generate_static_index_html()

    # 删除商品操作
    def delete_model(self, request, obj):

        pass

# 删除sku表
class SKUAdmin(admin.ModelAdmin):

    def save_model(self, request, obj, form, change):
        obj.save()
        generate_static_sku_detail_html.delay(obj.id)


    def delete_model(self, request, obj):
        obj.is_launched=False
        obj.save()
        generate_static_sku_detail_html.delay(obj.id)

class ImageAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        print(obj.image.url)

        generate_static_sku_detail_html.delay(obj.sku.id)

admin.site.register(Goods,GoodsAdmin)
admin.site.register(SKU,SKUAdmin)
admin.site.register(SKUImage,ImageAdmin)

